package com.ruoyi.logistic.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.logistic.domain.NetworkAbnormalData;
import com.ruoyi.logistic.domain.NetworkClient;
import com.ruoyi.logistic.domain.NetworkClientAndTag;
import com.ruoyi.logistic.domain.NetworkClientTag;
import com.ruoyi.logistic.service.INetworkAbnormalDataService;
import com.ruoyi.logistic.service.NetworkClientAndTagService;
import com.ruoyi.logistic.service.NetworkClientTagService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/network/clientTag")
@RestController
@Api(tags = "网点财务_客户标签")
public class NetworkClientTagController {
    @Autowired
    private NetworkClientTagService networkClientTagService;
    @Autowired
    private NetworkClientAndTagService networkClientAndTagService;

    @ApiOperation("显示所有客户标签列表")
    @GetMapping("/selectAll")
    public R selectAll(){
        List<NetworkClientTag> networkClientTagList = networkClientTagService.selectAll();
        if (networkClientTagList == null || networkClientTagList.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(networkClientTagList);
        }
    }
    @ApiOperation("添加客户标签")
    @PostMapping("/insert")
    public R insert(@RequestBody NetworkClientTag networkClientTag){
        Boolean isAdd = networkClientTagService.insert(networkClientTag);
        if (isAdd){
            return R.ok("添加成功");
        }else {
            return R.fail("添加失败");
        }
    }
    @ApiOperation("修改客户标签")
    @PostMapping("/update")
    public R update(@RequestBody NetworkClientTag networkClientTag){
        Boolean isUpdate = networkClientTagService.update(networkClientTag);
        if (isUpdate){
            return R.ok("修改成功");
        }else {
            return R.fail("修改失败");
        }
    }
    @ApiOperation("删除客户标签")
    @PostMapping("/deleteById")
    public R deleteById(Integer id){
        Boolean isDelete = networkClientTagService.deleteById(id);
        if (isDelete){
            return R.ok("删除成功");
        }else {
            return R.fail("删除失败");
        }
    }
    @ApiOperation("根据id批量查询")
    @GetMapping("/findByIds")
    public R findByIds(Integer[] clientTagId){
        List<NetworkClientTag> clientTags = networkClientTagService.findByIds(clientTagId);
        if (clientTags == null || clientTags.size() == 0){
            return R.fail("暂无数据");
        }else {
            return R.ok(clientTags);
        }
    }
    @ApiOperation("根据客户id查询标签")
    @GetMapping("/findByClientId")
    public R findByClientId(Integer clientId) {
        List<NetworkClientAndTag> clientAndTagList = networkClientAndTagService.findByClientId(clientId);
        if (clientAndTagList == null || clientAndTagList.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(clientAndTagList);
        }
    }
    @ApiOperation("返回客户的标签属性")
    @GetMapping("/resultClientTag")
    public R resultClientTag(Integer clientId){
        String result = networkClientAndTagService.findByClient(clientId);
        return R.ok(result);
    }

    @ApiOperation("查询大客户")
    @GetMapping("/findBigClient")
    public R findBigClient() {
        List<NetworkClient> clientList = networkClientAndTagService.findBigClient();
        if (clientList == null || clientList.size() == 0) {
            return R.fail("暂无数据");
        } else {
            return R.ok(clientList);
        }
    }
}
